package com.education.myproject.ui.main;

import com.education.myproject.App;
import com.education.myproject.bean.DouyuBean;
import com.education.myproject.bean.RoomBean;
import com.education.myproject.http.HttpHelper;

import java.util.List;
import java.util.Map;

import okhttp3.ResponseBody;
import retrofit2.Callback;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by zhonghang on 2016/10/4.
 */

public class MainModle implements MainContract.Modle {


    @Override
    public void getVertical(Map<String, String> params, Subscriber<DouyuBean> subscriber) {
        HttpHelper.getInstance().getVertical(params, subscriber);
    }

    @Override
    public void getVerticalFromDb(Subscriber<List<RoomBean>> subscriber) {
        Observable.create(new Observable.OnSubscribe<List<RoomBean>>() {
            @Override
            public void call(Subscriber<? super List<RoomBean>> subscriber) {
                List<RoomBean> list = App.getLiteOrm().query(RoomBean.class);
                subscriber.onNext(list);
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);

    }
}
